package com.zhx.ad.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *describe: 
 *
 *@author zhanghaixuan
 *@date 2019/02/01
 **/
@Slf4j
@Component
public class PreRequestFilter extends ZuulFilter {

	/**
	 * Zuul过滤器的类型
	 * @return
	 */
	@Override
	public String filterType() {
		return FilterConstants.PRE_TYPE;
	}
	/**
	 * 过滤器执行的顺序
	 * @return
	 */
	@Override
	public int filterOrder() {
		return 0;
	}
	/**
	 * 根据条件判断是否应该执行过滤器
	 * @return
	 */
	@Override
	public boolean shouldFilter() {
		return true;
	}
	/**
	 * 过滤器需要做的事情
	 * @return
	 */
	@Override
	public Object run() throws ZuulException {
		RequestContext currentContext = RequestContext.getCurrentContext();
		currentContext.set("startTime",System.currentTimeMillis());
		return null;
	}
}
